using System;
using System.Collections.Generic;
using System.Text;
using Csla;
using System.Data;
using Csla.Data;

namespace Active.Core
{
    /// <summary>
    /// The read only media infomation.
    /// </summary>
    [Serializable()]
    public class MediaInfo : ReadOnlyBase<MediaInfo>
    {
        #region Business Methods

        // TODO: add your own fields, properties and methods
        private int _id;
        private string _name = string.Empty;
        private decimal _advance;
        private decimal _brokerage;
        private MediaType _category;
        private int _dealTimes;

        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <value>The id.</value>
        public int Id
        {
            get { return _id; }
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Gets the advance.
        /// </summary>
        /// <value>The advance.</value>
        public decimal Advance
        {
            get { return _advance; }
        }

        /// <summary>
        /// Gets the brokerage.
        /// </summary>
        /// <value>The brokerage.</value>
        public decimal Brokerage
        {
            get { return _brokerage; }
        }

        /// <summary>
        /// Gets the category.
        /// </summary>
        /// <value>The category.</value>
        public MediaType Category
        {
            get { return _category; }
        }

        /// <summary>
        /// Gets the deal times.
        /// </summary>
        /// <value>The deal times.</value>
        public int DealTimes
        {
            get { return _dealTimes; }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion

        #region Factory Methods

        internal static MediaInfo GetMediaInfo(SafeDataReader dr)
        {
            return new MediaInfo(dr);
        }

        private MediaInfo()
        { /* require use of factory methods */ }

        private MediaInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }

        #endregion

        #region Data Access

        private void Fetch(SafeDataReader dr)
        {
            _id = dr.GetInt32("Id");
            _name = dr.GetString("Name");
            _advance = dr.GetDecimal("Advance");
            _brokerage = dr.GetDecimal("Brokerage");
            _category = (MediaType)dr.GetInt32("Category");
            _dealTimes = dr.GetInt32("DealTimes");
        }

        #endregion
    }
}

